package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getConnecting()){
            connection.setAutoCommit(false);//自动提交功能关闭
            String sql="UPDATE user1 " +
                    "SET password=?,nickname=?, age=? " +
                    "WHERE id=? ";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,"231424");
            ps.setString(2,"小明");
            ps.setInt(3,18);
            ps.setInt(4,2);
            int num =ps.executeUpdate();
            System.out.println(num>0?"修改成功":"修改失败");
//            connection.commit();
//            System.out.println("提交成功");
            connection.rollback();
            System.out.println("事务回滚，提交失败");
        } catch (SQLException e) {
           e.printStackTrace();
        }
    }
}
